﻿using System;

namespace Palindromes
{
  /// <summary>
  /// Represents palindrome console.
  /// </summary>
  internal class PalinromeConsole
  {
    #region private vars
    /// <summary>
    /// Console printer
    /// </summary>
    private readonly PalindromeConsolePrinter printer;

    /// <summary>
    /// Palindrome chacker
    /// </summary>
    private readonly PalindromChecker checker;
    #endregion

    #region public methods
    /// <summary>
    /// Constructor
    /// </summary>
    public PalinromeConsole()
    {
      printer = new PalindromeConsolePrinter();
      checker = new PalindromChecker(printer);
    }

    /// <summary>
    /// Starts palindrome console
    /// </summary>
    public void Run()
    {
      printer.WriteWelcome();

      string line;

      do
      {

        printer.WritePrompt();
        line = Console.ReadLine();
        if (!string.IsNullOrEmpty(line))
        {
          checker.Input = line;

          bool result = checker.IsMatch();

          printer.WriteResult(result);

        }

      } while (!string.IsNullOrEmpty(line));

      printer.WriteExit();
    }
    #endregion
  }
}
